package cn.lg.soar.message.client;

import cn.lg.soar.common.util.BeanCopier;
import cn.lg.soar.core.annotations.ApiClient;
import cn.lg.soar.message.api.constant.ModuleConst;
import cn.lg.soar.message.api.model.NoticeDTO;
import cn.lg.soar.message.api.service.INoticeApi;
import cn.lg.soar.message.entity.Notice;
import cn.lg.soar.message.service.INoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author luguoxiang
 * @date 2022/1/3
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ApiIgnore
@ApiClient("boot")
@RestController
@RequestMapping(ModuleConst.CLIENT_PATH + "/notice")
public class NoticeApiClient implements INoticeApi {

    @Autowired
    private INoticeService service;

    private final static BeanCopier<NoticeDTO, Notice> TO_ENTITY = BeanCopier.create(NoticeDTO.class, Notice.class);

    @PostMapping("broadcast")
    @Override
    public void broadcast(@RequestBody NoticeDTO dto) {
        Notice notice = TO_ENTITY.convert(dto);
        service.broadcast(notice);
    }

    @PostMapping("toUser")
    @Override
    public void toUser(@RequestParam NoticeDTO dto, @RequestBody List<Long> userIds) {
        Notice notice = TO_ENTITY.convert(dto);
        service.toUser(notice, userIds);
    }

}
